//
//  GXGameViewController.swift
//  GameCatchBall
//
//  Created by GuangXiao on 16/1/19.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import SnapKit
import AVFoundation
class GXGameViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()

        view = GXGameView(frame: UIScreen.mainScreen().bounds)
        countDownView.startCountdown()
        //两秒后移除
        UIView.animateWithDuration(2, animations: { () -> Void in
            self.countDownView.alpha = 0
            }) { (_) -> Void in
            self.countDownView.removeFromSuperview()
        }
        
//        GXSoundManager().playBGMusicWithFileName("bgMusic.wav")
        
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "backHomeNoti", name: "backHomeNotification", object: nil)
        
    }
    

    
    @objc private func backHomeNoti(){
        navigationController?.popToRootViewControllerAnimated(true)
//        dismissViewControllerAnimated(true, completion: nil)
    }
    
    //懒加载一个倒计时view
    private lazy var countDownView:CLCountdownView = {
        let countDownView = CLCountdownView.init(frame: ScreenSize)
        countDownView.backgroundColor = UIColor.blueColor()
        //倒计时的数字
        countDownView.startNumber = 0
        countDownView.numberFont = UIFont(name: "DIN Condensed", size: 30)
        countDownView.numberColor = UIColor.cyanColor()

        countDownView.finishText = "GO"
        countDownView.finishFont = UIFont.boldSystemFontOfSize(30)
        return countDownView
    }()
    
    
    override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
        let gameView = self.view as! GXGameView
        gameView.gameOver()
    }
    
}